// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of COnloadHandler and COnUnloadHandler.
//   $Id$


// OnLoadHandler.h : Declaration of the COnLoadHandler

#ifndef __ONLOADHANDLER_H_
#define __ONLOADHANDLER_H_

#include "resource.h"       // main symbols

#include "XFormsXFormsElement.h"

// OnLoadHandler.h : Declaration of the COnUnloadHandler


/////////////////////////////////////////////////////////////////////////////
// COnUnloadHandler
class ATL_NO_VTABLE COnUnloadHandler : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<COnUnloadHandler, &CLSID_OnUnloadHandler>,
	public IDispatchImpl<IOnUnloadHandler, &IID_IOnUnloadHandler, &LIBID_XFORMSLib>
{
public:
	COnUnloadHandler();
	virtual ~COnUnloadHandler()
	{
		m_pXForms = 0;
	}
DECLARE_REGISTRY_RESOURCEID(IDR_ONUNLOADHANDLER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(COnUnloadHandler)
	COM_INTERFACE_ENTRY(IOnUnloadHandler)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// IOnUnloadHandler
public:
	//<summary>
	//	Implementation of IDispatch::Invoke, deletes m_pXForms and 
	//	deregisters itself from m_pWin's event handler
	//</summary>
	STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo,UINT *puArgErr);
	//<summary>initialises private members and registers for events.</summary>
	//<param name="pForm">form to delete on unload of pWin3</param>
	//<param name="pWin3">Window object on which to register for unload</param>
	HRESULT Init(CXFormsXFormsElement * pForm, IHTMLWindow3 * pWin3);


private:
	CXFormsXFormsElement* m_pXForms;
	CComPtr<IHTMLWindow3> m_pWin;
};
OBJECT_ENTRY_AUTO(__uuidof(OnUnloadHandler), COnUnloadHandler)
#endif //__ONLOADHANDLER_H_
